﻿namespace Reviewer.Web.UI
{
    using System;
    using System.Reflection;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public abstract class MetadataPropertyControl : WebControl, INamingContainer
    {
        protected PropertyInfo propertyInfo;
        protected Label label = new Label();

        public MetadataPropertyControl(PropertyInfo property)
        {
            this.propertyInfo = property;
        }

        public string ValidationGroup { get; set; }

        protected override void CreateChildControls()
        {
            this.Controls.Clear();
            this.Controls.Add(new LiteralControl("<p>"));

            this.label = new Label();
            this.label.ID = this.ID + "_lb" + this.propertyInfo.Name;
            this.label.Text = global::Resources.EntityLabels.ResourceManager.GetString(this.propertyInfo.DeclaringType.Name + "_" + this.propertyInfo.Name) + ":";
            this.Controls.Add(this.label);

            this.Controls.Add(new LiteralControl("<br />"));

            this.CreateChildControlsEx();

            this.Controls.Add(new LiteralControl("</p>"));

        }

        protected abstract void CreateChildControlsEx();

        public abstract void Reset();

        public abstract void SetProperty(object item);
        public abstract void GetProperty(object item);
    }
}